import { createVNode, render } from "vue";
import Toast from "@/components/Toast.vue";
let time: number | null = null;
export const toast = (text: string, duration = 1500): void => {
  const div = document.createElement("div");
  div.setAttribute("class", "toast-box");
  document.body.appendChild(div);
  const NODE = createVNode(Toast, { text });
  render(NODE, div);
  time && clearTimeout(time);
  time = setTimeout(() => {
    render(null, div);
    const toastList = document.body.querySelectorAll(".toast-box");
    for (let i = 0; i < toastList.length; i++) {
      document.body.removeChild(toastList[i]);
    }
  }, duration);
};
